package com.zenob.common.log;

import java.io.IOException;
import java.io.InputStream;

public class LogOutputConsole implements LogOutput {

	public void log(int logLevel, String TAG, Object message, Throwable t) {
		log(logLevel, TAG, message+" "+t.toString());
	}
	
	public void log(int logLevel, String TAG, Object message) {
		
		if(logLevel < Log.LOG_LEVEL) return; 
		
		StringBuffer sb = new StringBuffer();
		
		sb.append("|");
		
		sb.append(logLevelToString(logLevel));
		
		sb.append("|");
		
		if(TAG.length()>24) {
			sb.append(TAG.substring(0, 24));
			sb.append("]");
		}
		else {
			int len = 24-TAG.length();
			sb.append(TAG);
			sb.append("| ");
			
			while(len>0) { sb.append(" "); len--;}
		}
		
		if(logLevel==Log.LEVEL_TRACE) sb.append("\t");

		sb.append(message);
		
		String logString = sb.toString();
				
		logConsole(logString);

	}

	private String logLevelToString(int logLevel) {
		
		switch (logLevel) {
		
		case Log.LEVEL_FATAL:
			return "FAT";
			
		case Log.LEVEL_ERROR:
			return "ERR";
			
		case Log.LEVEL_WARN:
			return "WAR";
			
		case Log.LEVEL_INFO:
			return "INF";
			
		case Log.LEVEL_DEBUG:
			return "DEB";	
			
		case Log.LEVEL_TRACE:
			return "TRA";	
		
		default:
			return "TRA";
		}
		
	}
	
	private void logConsole(String logString) {
		System.out.println(logString);
	}
	

	




	public InputStream getInputStream() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}




	public void releaseInputStream() throws IOException {
		// TODO Auto-generated method stub
		
	}
}
